Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to check for uninitialized numbers #1904

Merged
merged 5 commits into from
Nov 10, 2021
Merged

Conversation

camelid
Copy link
Member

@camelid camelid commented Oct 26, 2021

Closes #1340.

Companion rustc PR that implements this in the Miri engine: rust-lang/rust#88670

r? @RalfJung

@camelid
Copy link
Member Author

camelid commented Oct 26, 2021

(Some of these commits should probably be squashed together, but I think I'll wait until it's closer to being merged before doing so.)

src/bin/miri.rs Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@camelid
Copy link
Member Author

camelid commented Nov 3, 2021

By the way, let me know if/when you want me to squash :)

@RalfJung
Copy link
Member

RalfJung commented Nov 5, 2021

Yeah this looks ready, so please squash. :)

@camelid camelid force-pushed the uninit-num branch 3 times, most recently from ef28253 to c4f067e Compare November 9, 2021 21:16
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 10, 2021
miri: Detect uninitialized integers and floats

Part of rust-lang/miri#1340.

Companion Miri PR: rust-lang/miri#1904

r? `@RalfJung`
README.md Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

@camelid could you rebase on top of master and then also update the rust-version file so that it picks up your rustc changes?

This commit adds a `-Zmiri-check-number-initialization` flag to check
that integers and floats are initialized.

This commit also changes some shims to write at type `MaybeUninit<...>`
in order to prevent spurious errors from the uninit check.
@camelid
Copy link
Member Author

camelid commented Nov 10, 2021

This has no effect when -Zmiri-disable-validation is present.

Should I add a test for this, or is it not necessary?

@RalfJung
Copy link
Member

Should I add a test for this, or is it not necessary?

I don't think that is necessary.

So that we get rust-lang/rust#88670.
@RalfJung
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 10, 2021

📌 Commit 6dd1082 has been approved by RalfJung

@bors
Copy link
Collaborator

bors commented Nov 10, 2021

⌛ Testing commit 6dd1082 with merge a8b976e...

@camelid
Copy link
Member Author

camelid commented Nov 10, 2021

Thanks again for your help with this change! ❤️

@bors
Copy link
Collaborator

bors commented Nov 10, 2021

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing a8b976e to master...

@bors bors merged commit a8b976e into rust-lang:master Nov 10, 2021
@camelid camelid deleted the uninit-num branch November 10, 2021 20:32
@camelid
Copy link
Member Author

camelid commented Nov 10, 2021

I'll try to open a submodule sync later today.

bors bot added a commit to taiki-e/atomic-memcpy that referenced this pull request Feb 13, 2022
1: Remove miri hack r=taiki-e a=taiki-e

Use currently use a hack to avoid rust-lang/rust#69488 and to make sure that Miri errors for  atomic load/store of integers containing uninitialized bytes (which is probably not a problem and uncharted territory at best [1] [2] [3], and can be detected by `-Zmiri-check-number-validity` [4]), do not mask Miri errors for the use of uninitialized bytes (which is definitely a problem).

https://github.com/taiki-e/atomic-memcpy/blob/3507fef17534e4825b2b303d04702b4678e29dd0/src/lib.rs#L426-L450

[1]: crossbeam-rs/crossbeam#315 
[2]: rust-lang/unsafe-code-guidelines#158 
[3]: rust-lang/unsafe-code-guidelines#71 
[4]: rust-lang/miri#1904 

However, this actually causes another "unsupported operation" Miri error.

```
error: unsupported operation: unable to turn pointer into raw bytes
   --> /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:701:9
    |
701 |         copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
    |
    = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
```


Co-authored-by: Taiki Endo <te316e89@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to flag uninitialized integers as UB
3 participants